/**
 * Created by FreezeSoul on 2016/5/19.
 */
define([
        'angular',
        'jquery',
        'Handsontable',
        'app/modules/dataset/define'
    ],
    function (angular, $, Handsontable) {
        angular.module('ad.dataset')
            .directive('initExcelTable', [function () {
                return {
                    scope: {
                        excelData: '='
                    },
                    link: function ($scope, $elm, $attrs, $ctrl) {
                        $scope.$watch('excelData', function (newValue, oldValue) {
                            if (newValue) {
                                $($elm[0]).empty();
                                $scope.$parent.handsontable = new Handsontable($elm[0], {
                                    data: newValue,
                                    rowHeaders: true,
                                    colHeaders: true,
                                    stretchH: 'all',
                                    //autoColumnSize: true,
                                    //colWidths: 150,
                                    sortIndicator: true,
                                    columnSorting: true,
                                    contextMenu: true
                                });
                            }
                        }, true);
                    }
                };
            }
            ]);
    });